package com.example.demo.controller;

import com.example.comon.domain.LoginUser;
import com.example.comon.domain.R;
import com.example.comon.utils.UserUtil;
import com.example.demo.domain.Bo.AddTiaoxiuBo;
import com.example.demo.domain.Bo.TiaoxiuListBo;
import com.example.demo.domain.Tiaoxiu;
import com.example.demo.domain.Vo.TiaoxiuVo;
import com.example.demo.service.ITiaoxiuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/tiaoxiuApplication")
@Api(value = "tiaoxiuApplication",tags = "调休申请控制器")
public class TiaoxiuApplicationController {

    @Autowired
    private ITiaoxiuService tiaoxiuService;


    @GetMapping("/getTiaoxiuList")
    @ApiOperation("获取调休申请列表")
    public R<List<TiaoxiuVo>> getTiaoxiuList(TiaoxiuListBo bo){
        Tiaoxiu tiaoxiu = new Tiaoxiu();
        tiaoxiu.setTiaoxiuId(bo.getEmployeeId());
        List<TiaoxiuVo>list = tiaoxiuService.selectTiaoxiu(tiaoxiu);
        return R.success(list);
    }

    @PostMapping("/addTiaoxiu")
    @ApiOperation("增加调休申请")

    public R<Tiaoxiu> addTiaoxiu(@RequestBody AddTiaoxiuBo bo){
        Tiaoxiu tiaoxiu = new Tiaoxiu();
        tiaoxiu.setEmployeeId(bo.getEmployeeId());
        tiaoxiu.setTiaoxiuReason(bo.getTiaoxiuReason());
        tiaoxiu.setTiaoxiuStartTime(bo.getTiaoxiuStartTime());
        tiaoxiu.setTiaoxiuEndTime(bo.getTiaoxiuEndTime());
        tiaoxiu.setTiaoxiuDays(bo.getTiaoxiuDays());
        tiaoxiuService.insertTiaoxiu(tiaoxiu);
        return R.success(tiaoxiu);
    }

    @PostMapping("/updateTiaoxiuById")
    @ApiOperation("修改调休申请")
    public R updateTiaoxiuById(@RequestBody Tiaoxiu tiaoxiu) {
        tiaoxiuService.updateTiaoxiuById(tiaoxiu);
        return R.success();
    }

    @DeleteMapping("/delTiaoxiuById")
    @ApiOperation("删除调休申请")
    public R delTiaoxiuById(long tiaoxiuId){
        tiaoxiuService.delTiaoxiuById(tiaoxiuId);
        return R.success();
    }

}
